/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 10:14:50
 * @LastEditors: upholdjx 1373577124@qq.com
 * @LastEditTime: 2023-07-09 14:42:03
 */
import { getAreaObj } from '@/utils/util'
import { cloneDeep } from 'lodash-es'
import { revertUTF8 } from '@/views/oneStopOffice/utils/index'
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label:'考核人姓名',
			prop:'userName'
		},
		{
			label:'考核人身份证',
			prop:'idCard'
		},
		{
			label:'考核类型',
			prop:'examineType',
			custome:'tag',
			dicData:[
				{label:'正式',value:'0',type:'success'},
				{label:'模拟',value:'1',type:'primary'}
			]
		},
		{
			label:'考试名称',
			prop:'taskName'
		},
		{
			label:'考核分数(分)',
			prop:'maxScore',
		},
		{
			label:'考核开始时间',
			prop:'updateTime'
		},
		{
			label:'考核用时(分钟)',
			prop:'useTime'
		},
		{
			label:'考核结果',
			prop:'passed',
			custome:'tag',
			dicData:[
				{label:'未通过',value:'0',type:'danger'},
				{label:'通过',value:'1',type:'success'}
			]
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

// 新增编辑
export const BaseFormConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		
	],
}
export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'right',
	labelWidth: '120px',
	column:BaseFormConfig.column
}

export const baseConfig = {
	pageName: '考核记录管理',
	// 数据字典
	dictcodes: [''],
	rowKey: 'id',
	addLabel: '新增',
	// 删除插入
	tipLabel: 'taskName',
	api: {
		index: 'view_bscExamineUserRecord_page',
		delete: 'view_bscExamineUserRecord_del',
		detail:'view_bscExamineUserRecord_view'
		// add: 'view_bscTaskInfo_add',
		// edit: 'view_bscTaskInfo_edit',
	},
	auth: {
		index: 'view_bscExamineUserRecord_page',
		delete: 'view_bscExamineUserRecord_del',
		detail:'view_bscExamineUserRecord_view',
		// add: 'view_bscTaskInfo_add',
		// edit: 'view_bscTaskInfo_edit',
		// 批量设置
		mulitSet: 'mulitSet',
	},
	// 当前行操作按钮
	menuBtn: [
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'Detail',
			auth: '',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '85%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ 
				label:'考核人姓名',
				prop:'userName',
				span:8
			},
			{ 
				label:'考核人身份证号',
				prop:'idCard',
				span:8
			},
			{ 
				label:'考核类型',
				prop:'examineType',
				type:'select',
				dicData:[
				{label:'正式',value:'0',type:'success'},
				{label:'模拟',value:'1',type:'primary'}
				],
				span:8
			},
			{ 
				label:'考核分数(分)',
				prop:'maxScore',
				span:8
			},
			{ 
				label:'考核结果',
				prop:'passed',
				type:'select',
				dicData:[
					{label:'未通过',value:'0',type:'danger'},
					{label:'通过',value:'1',type:'success'}
				],
				span:8
			},
			{ 
				label:'考试名称',
				prop:'taskName',
				span:8
			},
		],
	},
	// 新增
	formConfig: {
		...BaseFormConfig,
		showBtn: true,
	},
	// 列表
	tableConfig,
	// 详情
	detailConfig: BaseFormConfig,
	// 处理发布日期
	beforeOnLoadFormate: async (params) => {
		const areasInfo: any = getAreaObj(params.areas_name, '')
		return Promise.resolve({
			...params,
			...areasInfo
		})
	},
	operateFormate:async (form,type) => {
		return new Promise((resolve, reject) => {
			let item = cloneDeep(form)
			let taskTimeRange = [item.startTime,item.endTime]
			const areasInfo: any = getAreaObj(item, '')
			if(item.idCard){
				item.idCard  = revertUTF8(item.idCard)
			}
			resolve({
					...item,
					...areasInfo,
					taskTimeRange
				}) 
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			let taskTimeRange = [item.startTime,item.endTime]
			const areasInfo: any = getAreaObj(item, '')
			if(item.idCard){
				item.idCard  = revertUTF8(item.idCard)
			}
			return {
				...item,
				...areasInfo,
				taskTimeRange
			}
		})
		return Promise.resolve(tableData)
	},
	// 新增处理
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const params = {
				...form,
				startTime:form.taskTimeRange[0],
				endTime:form.taskTimeRange[1],
				...areasObj
			}
			resolve(params)
		})
	},
}
